<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
            <el-form-item label="被指派人的名称" prop="assignName">
                <el-input
                    v-model="queryParams.assignName"
                    placeholder="请输入被指派人的名称"
                    clearable
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="分配时间" prop="assignTime">
                <el-date-picker clearable
                                v-model="queryParams.assignTime"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择分配时间">
                </el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-table v-loading="loading" :data="recordList" @selection-change="handleSelectionChange">
            <el-table-column label="被指派人" align="center" prop="assignName" />
            <el-table-column label="部门" align="center" prop="deptName" />
            <el-table-column label="指派时间" align="center" prop="assignTime" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.assignTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="文件名称" align="center" prop="fileName" />
            <el-table-column label="查看状态" align="center" prop="viewStatus">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.assign_view_status" :value="scope.row.viewStatus"/>
                </template>
            </el-table-column>
            <el-table-column label="OverDue" align="center" prop="overdueDays">
                <template slot-scope="scope">
                    <span :style="{ color: scope.row.overdueDays > 0 ? 'red':'normal' }">{{ scope.row.overdueDays }}天</span>
                </template>
            </el-table-column>
            <el-table-column label="紧急程度" align="center" prop="level">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.dcc_emergency_level" :value="scope.row.level"/>
                </template>
            </el-table-column>
            <el-table-column label="文件类型" align="center" prop="fileType">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.dcc_file_type" :value="scope.row.fileType"/>
                </template>
            </el-table-column>
            <el-table-column label="到期时间" align="center" prop="dueDate" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.dueDate) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="邮箱" align="center" prop="email" />
<!--            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--                <template slot-scope="scope">-->
<!--                    <el-button-->
<!--                        size="mini"-->
<!--                        type="text"-->
<!--                        icon="el-icon-edit"-->
<!--                        @click="handleUpdate(scope.row)"-->
<!--                        v-hasPermi="['business:record:edit']"-->
<!--                    >修改</el-button>-->
<!--                    -->
<!--                </template>-->
<!--            </el-table-column>-->
        </el-table>

        <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
        />
    </div>
</template>

<script>
import { listRecord, getRecord, delRecord, addRecord, updateRecord } from "@/api/business/assignRecord";

export default {
    name: "fileAssignRecord",
    dicts: ['dcc_file_type', 'assign_type', 'dcc_emergency_level','assign_view_status'],
    props: {
       fileAssignId: {
           type: String,
           default: null
       }
    },
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 文件浏览记录表格数据
            recordList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                sender: null,
                assignId: null,
                assignName: null,
                assignType: null,
                fileId: null,
                fileName: null,
                filePath: null,
                assignTime: null,
                fileType: null,
                viewStatus: null,
                level: null,
                dueDate: null,
                email: null
            },
            // 表单参数
            form: {}
        };
    },
    created() {
        this.getList();
    },
    methods: {
        /** 查询文件浏览记录列表 */
        getList() {
            this.loading = true;
            this.queryParams.fileId = this.fileAssignId
            listRecord(this.queryParams).then(response => {
                this.recordList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                id: null,
                sender: null,
                assignId: null,
                assignName: null,
                assignType: null,
                fileId: null,
                fileName: null,
                filePath: null,
                assignTime: null,
                fileType: null,
                viewStatus: null,
                level: null,
                dueDate: null,
                createTime: null,
                createBy: null,
                updateTime: null,
                updateBy: null,
                remark: null,
                email: null
            };
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length!==1
            this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.title = "添加文件浏览记录";
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            const id = row.id || this.ids
            getRecord(id).then(response => {
                this.form = response.data;
                this.open = true;
                this.title = "修改文件浏览记录";
            });
        }
    }
};
</script>
